﻿<UserControl 
    x:Class="Poet.Views.SplitableTextEditorView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:views="clr-namespace:Poet.Views"
    Name="This"> 
    
    <UserControl.Resources>
        <Style TargetType="ScrollViewer" BasedOn="{StaticResource ResourceKey={x:Type ScrollViewer}}">
            <EventSetter Event="PreviewMouseWheel" Handler="OnMouseWheel"/>
        </Style>
        <Style TargetType="ScrollBar" BasedOn="{StaticResource ResourceKey={x:Type ScrollBar}}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding ElementName=PART_ScrollViewer, Path=HorizontalScrollBarVisibility}" Value="Disabled">
                    <Setter Property="Margin" Value="0,0,0,17"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
        <BooleanConverter OnTrue="{Localizing Collapse}" OnFalse="{Localizing Split}" x:Key="SplitButtonTooltipConverter"/>
    </UserControl.Resources>
       
    <Grid>
        
        <Grid.RowDefinitions>
            <RowDefinition Height="1.0*" Name="Row0"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="0.0*" Name="Row2"/>
        </Grid.RowDefinitions>
        
        <views:TextEditorView x:Name="TextEditorView"/>

        <StackPanel  
            Width="17"
            Height="17" 
            Background="WhiteSmoke"
            HorizontalAlignment="Right" 
            VerticalAlignment="Bottom" >
            <ToggleButton 
                Width="17"
                Height="17"
                Focusable="False"
                IsChecked="{Binding IsSplited, ElementName=This}"
                Opacity="0.5" 
                ToolTip="{Binding IsSplited, ElementName=This, Converter={StaticResource SplitButtonTooltipConverter}}">
                <ToggleButton.Resources>
                    <BooleanConverter x:Key="AngleConverter" OnTrue="M 1 0.5 L 4.5 4 L 8 0.5 M 1 7 L 8 7" OnFalse="M 1 4 L 4.5 0.5 L 8 4 M 1 7 L 8 7"/>
                </ToggleButton.Resources>
                <Path 
                    Data="{Binding IsSplited, ElementName=This, Converter={StaticResource AngleConverter}}"
                    Stroke="#FF666666"
                    StrokeThickness="2"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    RenderTransformOrigin="0.5,0.5">
                </Path>
            </ToggleButton>

        </StackPanel>
        
        <GridSplitter
            ShowsPreview="False"
            Grid.Row="1"
            Name="Splitter"  
            Focusable="False"
            Visibility="Collapsed" 
            Height="5" 
            VerticalAlignment="Center"
            HorizontalAlignment="Stretch" 
            Background="Silver"
            Opacity="0.2"/>
        
        <ContentControl Grid.Row="2" Name="ContentView" VerticalAlignment="Stretch"/>
        
    </Grid>

</UserControl>
